package com.qiuzhiyi.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.InputFilter;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.widget.EditText;
import android.widget.TextView;

import com.li.utils.InputFilterUtil;
import com.li.utils.KeyboardUtil;
import com.li.utils.ToastUtil;
import com.nex3z.flowlayout.FlowLayout;
import com.qiuzhiyi.R;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;


/**
 * Author: Li
 * Date: 2018/1/22 0022
 * Description: 搜索界面
 */

public class SearchActivity extends AppCompatActivity {

    @BindView(R.id.flow_layout)
    FlowLayout mFlowLayout;
    @BindView(R.id.et_condition)
    EditText mEtCondition;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_search);
        ButterKnife.bind(this);
        mEtCondition.setImeOptions(EditorInfo.IME_ACTION_SEARCH);

        mEtCondition.setFilters(new InputFilter[]{new InputFilterUtil.NoEmojiFilter()});
        mEtCondition.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                getResult();
                return false;
            }
        });
    }

    @OnClick({R.id.img_back, R.id.txt_search})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.img_back:
                finish();
                break;
            case R.id.txt_search:
                getResult();
                break;
        }
    }
    private void getResult(){
        KeyboardUtil.hideKeyboard(SearchActivity.this,mEtCondition);
        if (TextUtils.isEmpty(mEtCondition.getText().toString())) {
            ToastUtil.showToast(SearchActivity.this,"搜索条件不能为空");
            return;
        }
        Intent intent=new Intent(SearchActivity.this,SearchListActivity.class);
        intent.putExtra("name",mEtCondition.getText().toString());
        startActivity(intent);
        finish();
    }
}
